# @Version        : 1.0
# @Update Time    : 2025/3/13 15:51
# @File           : cart_service.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息

import logging


class CartService:
    def __init__(self):
        self.items = [
            {"name": "芒果", "image_path": "assets/mango.png", "spec": "3kg", "price": 5.4, "quantity": 3},
            {"name": "葡萄", "image_path": "assets/grapes.png", "spec": "2kg", "price": 2.1, "quantity": 1},
            {"name": "草莓", "image_path": "assets/product1.png", "spec": "2kg", "price": 4.7, "quantity": 2},
            {"name": "草莓2", "image_path": "assets/product2.png", "spec": "2kg", "price": 4.7, "quantity": 2},
            {"name": "草莓3", "image_path": "assets/product3.png", "spec": "2kg", "price": 4.7, "quantity": 2},
            {"name": "草莓4", "image_path": "assets/product4.png", "spec": "2kg", "price": 4.7, "quantity": 2},
            {"name": "草莓5", "image_path": "assets/avocado.png", "spec": "2kg", "price": 4.7, "quantity": 2}
        ]

    def get_cart_items(self):
        # 检查每个商品是否有price字段，如果没有则设置默认值
        for item in self.items:
            if "price" not in item:
                logging.warning(f"商品 {item.get('name', '未知')} 缺少 price 字段，设置默认价格为 0.0")
                item["price"] = 0.0  # 设置默认价格为0.0
        return self.items
